package com.hornsun.data.repository;

import com.hornsun.data.dbo.Activities;
import com.hornsun.data.dbo.ActivitiesExample;
import com.hornsun.data.repository.mapper.ActivitiesMapper;
import com.hornsun.util.LittleUtil;
import com.hornsun.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 编译中... on 2018/7/21.
 */
@Repository
public class ActivitiesRepository {
    @Autowired
    private ActivitiesMapper activitiesMapper;

    public List<Activities> getActivitiesByClientGuid(String guid, int page){
        ActivitiesExample activitiesExample = new ActivitiesExample();
        activitiesExample.setOrderByClause(StrUtil.toDesc("time"));
        ActivitiesExample.Criteria criteria = activitiesExample.createCriteria();
        criteria.andClientGuidEqualTo(guid);
        return activitiesMapper.selectByExampleWithRowbounds(activitiesExample, LittleUtil.rowBounds(page,10));
    }

    public void insertActivities(Activities activities){
        if (activitiesMapper.insertSelective(activities)!=1){
            throw new IllegalArgumentException("insert activities failed by activities"+activities);
        };
    }
}
